package com.hup.winHolderService.framework.model;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * 与spring的异常结构体一致,只是去掉了path字段
 *
 * @author hugan
 * @date 2023/7/9
 */
@Data
@NoArgsConstructor
public class ExceptionResult {

    private long timestamp;
    private int status;
    private String error;
    private String message;

    public interface BaseResultException {

        HttpStatus getStatus();

        String getRespMessage();

        default void doLog() {
        }

        default ResponseEntity<ExceptionResult> toResult() {
            HttpStatus status = getStatus();
            ExceptionResult res = new ExceptionResult();
            res.timestamp = System.currentTimeMillis();
            res.status = status.value();
            res.error = status.getReasonPhrase();
            res.message = getRespMessage();
            return ResponseEntity.status(status.value()).body(res);
        }

    }

}
